using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public class RectTube : PPBase
	{
		[Header("Basic parameters")]
		public float width1 = 1f;

		public float width2 = 0.6f;

		public float length1 = 1f;

		public float length2 = 0.6f;

		public float height = 1f;

		public bool cap1;

		public float capThickness1 = 0.2f;

		public bool cap2;

		public float capThickness2 = 0.2f;

		[Header("Segments")]
		public int widthSegs = 2;

		public int lengthSegs = 2;

		public int heightSegs = 2;

		public int capSegs = 2;

		[Header("Mapping Coordinates")]
		public bool generateMappingCoords = true;

		public bool realWorldMapSize;

		public Vector2 UVOffset = new Vector2(0f, 0f);

		public Vector2 UVTiling = new Vector2(1f, 1f);

		[Header("Others")]
		public bool flipNormals;

		protected override void CreateMesh()
		{
			m_mesh.name = "RectTube";
			length1 = Mathf.Clamp(length1, 1E-05f, 10000f);
			width1 = Mathf.Clamp(width1, 1E-05f, 10000f);
			this.length2 = Mathf.Clamp(this.length2, 1E-05f, length1);
			width2 = Mathf.Clamp(width2, 1E-05f, width1);
			height = Mathf.Clamp(height, 1E-05f, 10000f);
			if (cap1)
			{
				capThickness1 = Mathf.Clamp(capThickness1, 1E-05f, height);
				capThickness2 = Mathf.Clamp(capThickness2, 1E-05f, height - capThickness1);
			}
			else
			{
				capThickness1 = Mathf.Clamp(capThickness1, 1E-05f, height);
				capThickness2 = Mathf.Clamp(capThickness2, 1E-05f, height);
			}
			lengthSegs = Mathf.Clamp(lengthSegs, 1, 100);
			widthSegs = Mathf.Clamp(widthSegs, 1, 100);
			heightSegs = Mathf.Clamp(heightSegs, 1, 100);
			capSegs = Mathf.Clamp(capSegs, 1, 100);
			float num = (cap1 ? capThickness1 : 0f);
			float num2 = (cap2 ? capThickness2 : 0f);
			float num3 = length1 * 0.5f;
			float num4 = width1 * 0.5f;
			float num5 = this.length2 * 0.5f;
			float num6 = width2 * 0.5f;
			float num7 = height * 0.5f;
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, 0f - num3), m_rotation * Vector3.up, m_rotation * Vector3.right, width1, height, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, num3), m_rotation * Vector3.up, m_rotation * Vector3.left, width1, height, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f - num4, 0f, 0f), m_rotation * Vector3.up, m_rotation * Vector3.back, length1, height, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(num4, 0f, 0f), m_rotation * Vector3.up, m_rotation * Vector3.forward, length1, height, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			float length = height - num2 - num;
			float y = (num - num2) * 0.5f;
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, y, 0f - num5), m_rotation * Vector3.up, m_rotation * Vector3.right, width2, length, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, y, num5), m_rotation * Vector3.up, m_rotation * Vector3.left, width2, length, widthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f - num6, y, 0f), m_rotation * Vector3.up, m_rotation * Vector3.back, this.length2, length, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(num6, y, 0f), m_rotation * Vector3.up, m_rotation * Vector3.forward, this.length2, length, lengthSegs, heightSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			float num8 = (num4 + num6) * 0.5f;
			float num9 = (num3 + num5) * 0.5f;
			float length2 = num4 - num6;
			float length3 = num3 - num5;
			if (cap1)
			{
				CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f - num7, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.left, width1, length1, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
				CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f - num7 + num, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.left, width2, this.length2, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			}
			else
			{
				CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, 0f - num7, 0f - num9), m_rotation * Vector3.forward, m_rotation * Vector3.right, width1, width2, length3, 0f, widthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
				CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, 0f - num7, num9), m_rotation * Vector3.back, m_rotation * Vector3.left, width1, width2, length3, 0f, widthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
				CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f - num8, 0f - num7, 0f), m_rotation * Vector3.right, m_rotation * Vector3.back, length1, this.length2, length2, 0f, lengthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
				CreateTrapezoid(pivotOffset + m_rotation * new Vector3(num8, 0f - num7, 0f), m_rotation * Vector3.left, m_rotation * Vector3.forward, length1, this.length2, length2, 0f, lengthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
			}
			if (cap2)
			{
				CreatePlane(pivotOffset + m_rotation * new Vector3(0f, num7, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, width1, length1, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
				CreatePlane(pivotOffset + m_rotation * new Vector3(0f, num7 - num2, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, width2, this.length2, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, !flipNormals);
				return;
			}
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, num7, 0f - num9), m_rotation * Vector3.forward, m_rotation * Vector3.right, width1, width2, length3, 0f, widthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f, num7, num9), m_rotation * Vector3.back, m_rotation * Vector3.left, width1, width2, length3, 0f, widthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(0f - num8, num7, 0f), m_rotation * Vector3.right, m_rotation * Vector3.back, length1, this.length2, length2, 0f, lengthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
			CreateTrapezoid(pivotOffset + m_rotation * new Vector3(num8, num7, 0f), m_rotation * Vector3.left, m_rotation * Vector3.forward, length1, this.length2, length2, 0f, lengthSegs, 2, generateMappingCoords, realWorldMapSize, UVOffset, UVTiling, flipNormals);
		}
	}
}
